package util

import "time"

var(
	now = time.Now()
	week = now.Weekday()
	offset  int
)
func init()  {
	offset = int(time.Monday-week)
	if offset > 0 {
		offset = -6
	}
}

//周一
func Weekstart() time.Time {
	StartDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
	return StartDate.AddDate(0, 0, offset)
}
//周末
func Weekend() time.Time {
	EndDates := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999999999, time.Local)
	return EndDates.AddDate(0, 0,int((week+1)-week))
}

func Monthstart()  time.Time{
	currentLocation := now.Location()
	firstOfMonth := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, currentLocation)//月初开始
	return  firstOfMonth
}
func Monthend() time.Time {
	currentLocation := now.Location()
	EndOfMonth := time.Date(now.Year(), now.Month(), 1, 23, 59, 59, 999999999, currentLocation) //月初开始
	lastOfMonth := EndOfMonth.AddDate(0, 1, -1)
	return lastOfMonth
}

func Todaystart() time.Time{
	currentYear,currentMonth,_ := now.Date()
	currentLocation := now.Location()
	firstOfDay := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)
	return firstOfDay.AddDate(0,0,int(now.Day()-1))
}
func Todayend() time.Time  {
	currentYear,currentMonth,_ := now.Date()
	currentLocation := now.Location()
	lastOfDay := time.Date(currentYear, currentMonth, 1, 23, 59, 59, 999999999, currentLocation)//今天结束
	return lastOfDay.AddDate(0,0,int(now.Day()-1))
}
func Yesterdaystart()time.Time  {
	currentYear,currentMonth,_ := now.Date()
	firstOfYesterday := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, time.Local)//昨天开始
	return firstOfYesterday.AddDate(0,0,int(now.Day()-2))
}
func Yesterdayend()time.Time  {
	currentYear,currentMonth,_ := now.Date()
	lastOfYesterday := time.Date(currentYear, currentMonth, 1, 23, 59, 59, 999999999, time.Local)//昨天结束
	return  lastOfYesterday.AddDate(0,0,int(now.Day()-2))
}




